package com.cskaoyan.javase.homework.day02;

import java.util.Scanner;

/**
 * @description: 方法的练习
 * @author: wuguidong@cskaoyan.onaliyun.com
 **/


/**
 * > 把day01作业中的两道题，用方法进行改造。比如求平均分的方法，求税后收入的方法等
 * - 需要把原先在main方法中的代码提取出来作为一个方法，然后在main中调用测试它
 * - 需要注意方法的命名规范
 */
public class GradeDemo {
    public static void main(String[] args) {
        //键盘输入 三门学科成绩，然后，分别求出 三科成绩的平均分，最低分，最高分，三科的总分

        System.out.print("请输入三门课成绩：");
        Scanner sc = new Scanner(System.in);
        double mathScore = sc.nextDouble();
        double chineseScore = sc.nextDouble();
        double englishScore = sc.nextDouble();

        //提取方法的快捷键: ctrl + alt + m

        System.out.println("三门课平均成绩为：" + getAverage(mathScore, chineseScore, englishScore));
        System.out.println("三门课中最低分" + getMinScore(mathScore, chineseScore, englishScore));
        System.out.println("三门课中最高分" + getMaxScore(mathScore, chineseScore, englishScore));
        System.out.println("三门课总和" + (mathScore + chineseScore + englishScore));

    }


    //两次三目运算符求出最小值
    public static double getMinScore(double mathScore, double chineseScore, double englishScore) {
        double tempMinScore = (mathScore < chineseScore) ? mathScore : chineseScore;
        return (tempMinScore < englishScore) ? tempMinScore : englishScore;
    }

    //两次三目运算符求出最大值
    public static double getMaxScore(double mathScore, double chineseScore, double englishScore) {
        double tempMaxScore = (mathScore > chineseScore) ? mathScore : chineseScore;
        return (tempMaxScore > englishScore) ? tempMaxScore : englishScore;
    }


    //求平均值
    public static double getAverage(double mathScore, double chineseScore, double englishScore) {
        return (mathScore + chineseScore + englishScore) / 3;
    }


}

